1 /*
2 * Title: S/MIME Project
3 * Description: S/MIME email sending capabilities
4 * @Author Vladimir Radisic
5 * @Version 2.0.1
6 */
7
8
9 package org.webdocwf.util.smime.cms;
10
11
12 import org.webdocwf.util.smime.exception.SMIMEException;
13 import org.webdocwf.util.smime.der.DERSetPr;
14 import org.webdocwf.util.smime.der.DERObjectIdentifier;
15 import org.webdocwf.util.smime.der.DERIA5String;
16 import org.webdocwf.util.smime.der.DERSequence;
17 import org.webdocwf.util.smime.der.DERPrintableString;
18
19
20 /***
21 * RelativeDistinguishedName class is DER encoded container represented in ASN.1
22 * notation according to RFC2630. It is used to hold just one information about
23 * owner or issuer of certificate (it can be name or country etc.). Collection
24 * of RelativeDistinguishedName builds IssuerName. Details about ASN.1 notation
25 * are described in class IssuerAndSerialNumber. RelativeDistinguishedName class
26 * is used only by addParticularRelativeDN method of IssuerAndSerialNumber.
27 */
28 public class RelativeDistinguishedName extends DERSetPr {
29
30 /***
31 * Indicator for enable/disable of use particular methods.
32 */
33 private int enable = 1;
34
35 /***
36 * Constructs empty RelativeDistinguishedName object.
37 * @exception SMIMEException thrown in super class constructor.
38 */
39 public RelativeDistinguishedName() throws SMIMEException {}
40
41 /***
42 * Constructs specific RelativeDistinguishedName object according to id0. This
43 * constructor has two different forms, depend on parameter typeConstruction0,
44 * which can be: DOT_SEPARATED_ARRAY or NAME_STRING. If typeConstruction0 parameter
45 * is DOT_SEPARATED_ARRAY then id0 definition is represented by numbers separated
46 * with dots (example: "2.5.4.6"). In case of NAME_STRING, id0 definition is name
47 * of object identifier (example: "COUNTRYNAME").
48 * @param id0 define Object Identifier in representation determined by second
49 * parameter - typeConstruction0.
50 * @param typeConstruction0 can take values DOT_SEPARATED_ARRAY and NAME_STRING
51 * @param value0 value of attribute of corresponding type defined by
52 * id0 and typeConstruction0
53 * @exception SMIMEException if wrong type of parameters are passed to the
54 * constructor. Also, it can be thrown by super class constructor.
55 */
56 public RelativeDistinguishedName(String id0, String typeConstruction0, String value0) throws SMIMEException {
57 this.setAttributeTypeAndValue(id0, typeConstruction0, value0);
58 enable = 2;
59 }
60
61 /***
62 * Constructs specific RelativeDistinguishedName object according to arrayID0.
63 * Array of numbers (arrayID0) is used for constructing object identifier. Every
64 * number in array represent one number between dots in object identifier string.
65 * @param arrayID0 array of given numbers (example: for COUNTRYNAME object
66 * identifier those numbers are 2, 5, 4 and 6)
67 * @param value0 value of corresponding attribute defined by id0 and
68 * typeConstruction0
69 * @exception SMIMEException if wrong type of parameters are passed to the
70 * constructor. Also, it can be thrown by super class constructor.
71 */
72 public RelativeDistinguishedName(int[] arrayID0, String value0) throws SMIMEException {
73 this.setAttributeTypeAndValue(arrayID0, value0);
74 enable = 3;
75 }
76
77 /***
78 * Sets type and value for particular attribute. For details about parameters
79 * look at second type of constructor.
80 * @param id0 same as in the second type of constructor.
81 * @param typeConstruction0 same as in the second type of constructor.
82 * @param value0 same as in the second type of constructor.
83 * @exception SMIMEException if method is performed twice for same object or if
84 * object wasn't constructed with the simplest constructor. Also, it can be
85 * thrown from super class addContent method.
86 */
87 public void setAttributeTypeAndValue(String id0, String typeConstruction0, String value0) throws SMIMEException {
88 if (enable == 4)
89 throw new SMIMEException(this, 1023);
90 else if (enable != 1)
91 throw new SMIMEException(this, 1024);
92 DERSequence seq = new DERSequence();
93 DERObjectIdentifier attribID = new DERObjectIdentifier(id0, typeConstruction0);
94
95 seq.addContent(attribID.getDEREncoded());
96 if (id0.equalsIgnoreCase("EMAILADDRESS") | id0.equalsIgnoreCase("1.2.840.113549.1.9.1")) {
97 DERIA5String atribString = new DERIA5String(value0);
98
99 seq.addContent(atribString.getDEREncoded());
100 } else {
101 DERPrintableString atribString = new DERPrintableString(value0);
102
103 seq.addContent(atribString.getDEREncoded());
104 }
105 super.addContent(seq.getDEREncoded());
106 enable = 4;
107 }
108
109 /***
110 * Sets type and value for particular attribute. For details about parameters
111 * look at third type of constructor.
112 * @param arrayID0 same as in the third type of constructor.
113 * @param value0 same as in the third type of constructor.
114 * @exception SMIMEException if method is performed twice for same object or if
115 * object wasn't constructed with the simplest constructor. Also, it can be
116 * thrown from super class addContent method.
117 */
118 public void setAttributeTypeAndValue(int[] arrayID0, String value0) throws SMIMEException {
119 if (enable == 4)
120 throw new SMIMEException(this, 1023);
121 else if (enable != 1)
122 throw new SMIMEException(this, 1024);
123 DERObjectIdentifier attribID = new DERObjectIdentifier(arrayID0);
124 DERPrintableString atribString = new DERPrintableString(value0);
125 DERSequence seq = new DERSequence();
126
127 seq.addContent(attribID.getDEREncoded());
128 seq.addContent(atribString.getDEREncoded());
129 super.addContent(seq.getDEREncoded());
130 enable = 4;
131 }
132 }
133
This page was automatically generated by Maven